import androidx.navigation.NamedNavArgument
import androidx.navigation.NavBackStackEntry
import androidx.navigation.NavType
import androidx.navigation.navArgument


class PersonInfoData {
    //定义数据模型
    data class PersonInfoDataArgs(
        val name : String,
        val phone : String,
        val age : Int,
        val email : String
    )

    //相当于定义静态方法，静态变量
    companion object{
        //1.定义路由
        val route = "PersonalInfoView?name={name},phone={phone},age={age},email={email}"

        //2.定义路由参数列表
        val aggumentList : MutableList<NamedNavArgument>
            get() = mutableListOf(
                navArgument("name"){
                    type = NavType.StringType
                    defaultValue = "name is null"
                    nullable = true
                },
                navArgument("phone"){
                    type = NavType.StringType
                    defaultValue = "phone is null"
                    nullable = true
                },
                navArgument("age"){
                    type = NavType.IntType
                    defaultValue = 0
                    nullable = false
                },
                navArgument(name = "email"){
                    type = NavType.StringType
                    defaultValue = "email is null"
                    nullable = true
                }
            )

        //3.解析路由传递的参数
        fun parseArguments(backStackEntry: NavBackStackEntry) : PersonInfoDataArgs{
            return PersonInfoDataArgs(
                name=backStackEntry.arguments?.getString("name") ?: "",
                phone=backStackEntry.arguments?.getString("phone") ?: "",
                age=backStackEntry.arguments?.getInt("age") ?: 0,
                email=backStackEntry.arguments?.getString("email") ?: "",
            )
        }

        //4.创建导航图的方法
        fun actionToPersonalInfoCompose(name : String,phone : String,age : Int,email: String):String{
             return "PersonalInfoView?name=${name},phone=$phone,age=$age,email=$email"
        }

    }
}